package DivorceSum4;

import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class DivorceSumReducer extends Reducer<DivorceCountBean, FloatWritable,DivorceCountBean,FloatWritable> {

     FloatWritable outValue = new FloatWritable();

    @Override
    protected void reduce(DivorceCountBean key, Iterable<FloatWritable> values, Reducer<DivorceCountBean, FloatWritable, DivorceCountBean, FloatWritable>.Context context) throws IOException, InterruptedException {
        /**
         * 创建统计变量
         */
        float totaLDivorce = 0;

        /**
         *  遍历的数据
         */
        for (FloatWritable value:values) {
            //value:表示每年全国的离婚登记数
            totaLDivorce += value.get();
        }
        outValue.set(totaLDivorce);
        context.write(key,outValue);
    }

}
